// 市场销售 / 入院管理

import r from '@/utils/request'
import { type ListResponseType, type ResponseType } from '../types'

enum API {
    orderGet = 'order/get',// 获取单条入院信息
    orderList = "/order/list", // 入院列表
    orderAdd = "/order/add", // 入院添加
    orderUpdate = "/order/update", // 入院修改
    orderDelete = "/order/delete", // 入院删除
    orderDeleteAll = "/order/deleteAll", // 入院批量删除
}

export interface orderGetResHealthAPI {
    id:           number;
    elderlyId:    number;
    oldillness:   string;
    nowillness:   string;
    otherillness: string;
    otherCase:    string;
}

export interface orderGetResAPI {
    id:             number;
    companyId:      number;
    name:           string;
    mobile:         string;
    photo:          string;
    gender:         number;
    birthday:       string;
    nativePlace:    string;
    nation:         string;
    idCard:         string;
    politics:       string;
    socialCard:     string;
    marriage:       string;
    eduLevel:       string;
    education:      string;
    resident:       string;
    address:        string;
    begId:          number;
    houseId:        number;
    state:          number;
    addTime:        string;
    addAccountId:   number;
    stateName:      string;
    begName:        string;
    addAccountName: string;
    houseName:      string;
    buildingName:   string;
    health:         orderGetResHealthAPI;
    selfCares:      any[];
    checkups:       any[];
    family:         any[];
}

export function orderGetAPI(id:number):Promise<ResponseType<orderGetResAPI>> {
    return r.get( API.orderGet + '/' + id )
}

export interface orderListParams {
    page: number
    pageSize: number
    name: string
    idCard: string
    begId: string
    mobile: number
    state:number
}

export interface orderListResAPI {
    id:             number;
    companyId:      number;
    elderlyId:      number;
    begId:          number;
    begName:        string;
    begPrice:       number;
    days:           number;
    startDate:      string;
    foodPrice:      number;
    servicePrice:   number;
    cashPledge:     number;
    livingPrice:    number;
    payDays:        number;
    state:          number;
    addTime:        string;
    addAccountId:   number;
    addAccountName: string;
    elderlyName:    string;
    elderlyPhoto:   string;
    elderlyGender:  string;
    elderlyIdCard:  string;
    houseName:      string;
    buildingName:   string;
    services:       string;
    files:          string;
}

export function getorderListAPI(Params:orderListParams):Promise<ListResponseType<orderListResAPI[]>> {
    return r.get(API.orderList,Params)
}

export interface  orderAddParamsService {
    id?: number,
    serviceId: number;
    companyId?: number
    name?: string
    content?: string
}

export interface  orderAddParamsFile {
    file: string;
}

export interface  orderAddParams {
    id: number;
    elderlyId:    number;
    begId:        number | null;
    begPrice:     number | null;
    days:         number | null;
    startDate:    string;
    foodPrice:    number | null;
    servicePrice: number | null;
    cashPledge:   number | null;
    livingPrice:  number | null;
    payDays:      number | null;
    state:        number;
    services:     orderAddParamsService[];
    files:        orderAddParamsFile[];
}

export interface orderFile {
    id:      number;
    orderId: number;
    file:    string;
}

export interface orderAddResAPI {
    id:             number;
    companyId:      number;
    elderlyId:      number;
    begId:          number;
    begName:        string;
    begPrice:       number;
    days:           number;
    startDate:      string;
    foodPrice:      number;
    servicePrice:   number;
    cashPledge:     number;
    livingPrice:    number;
    payDays:        number;
    state:          number;
    addTime:        string;
    addAccountId:   number;
    addAccountName: string;
    elderlyName:    string;
    elderlyPhoto:   string;
    elderlyGender:  string;
    elderlyIdCard:  string;
    houseName:      string;
    buildingName:   string;
    services:       any[];
    files:          orderFile[];
}

export function orderAddAPI(Params:orderAddParams):Promise<ResponseType<orderAddResAPI>> {
    return r.post(API.orderAdd,Params)
}

export interface orderUpdateParamsAndResService {
    id:             number;
    orderId:        number;
    serviceId:      number;
    serviceName:    string;
    serviceContent: string;
}

export interface orderUpdateParamsAndRes {
    id:             number;
    companyId:      number;
    elderlyId:      number;
    begId:          number;
    begName:        string;
    begPrice:       number;
    days:           number;
    startDate:      string;
    foodPrice:      number;
    servicePrice:   number;
    cashPledge:     number;
    livingPrice:    number;
    payDays:        number;
    state:          number;
    addTime:        string;
    addAccountId:   number;
    addAccountName: string;
    elderlyName:    string;
    elderlyPhoto:   string;
    elderlyGender:  string;
    elderlyIdCard:  string;
    houseName:      string;
    buildingName:   string;
    services:       orderUpdateParamsAndResService[];
    files:          orderFile[];
}

export function orderUpdateAPI(Params:orderAddParams):Promise<ResponseType<orderUpdateParamsAndRes>> {
    return r.put(API.orderUpdate,Params)
}

export function orderDeleteAPI(id:number):Promise<ResponseType<null>> {
    return r.delete(API.orderDelete+'/'+id)
}

export function orderDeleteAllAPI(ids: number[]): Promise<ResponseType<string>> {
    return r.post(API.orderDeleteAll,ids)
}